/**
 * \license
 * Copyright Lassi Marttala 2013
 * 
 * This file is part of dlt2jpa.
 *
 * dlt2jpa is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * dlt2jpa is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with dlt2jpa.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.fizzl.dlt.message.parser;

import java.nio.ByteOrder;

import net.fizzl.dlt.ByteArrayUtils;
import net.fizzl.dlt.message.DltPayload;
import net.fizzl.dlt.message.DltPayloadArgument;

public class DltPayloadParser {

	public DltPayload fromByteArray(byte[] data, int numberOfArguments, ByteOrder byteOrder) {
		byte buf[] = data.clone();
		DltPayload ret = new DltPayload();
		for(int i=0;i<numberOfArguments;i++) {
			DltPayloadArgumentParser parser = new DltPayloadArgumentParser(byteOrder);
			DltPayloadArgument argument = parser.fromByteArray(buf);
			ret.addArgument(argument);
			int offset = argument.getLength();
			buf = ByteArrayUtils.removeHead(buf, offset);
		}
		return ret;
	}
}
